package com.kgc.util;

/**
 * @author hyj
 * @time 2024/4/3 14:10
 * @describe
 */

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class CodeTimeUtil {
    private static String codePass;
    private static ScheduledExecutorService executor;

    public void setCodePass(String code) {
        codePass = code;

        // 创建定时器任务，在一定时间后清除验证码
        if (executor == null || executor.isShutdown()) {
            executor =  new ScheduledThreadPoolExecutor(1);
            executor.schedule(() -> {
                codePass = null;
                // 设置清除验证码的延迟时间（这里设置为2分钟）
            }, 2, TimeUnit.MINUTES);
        }
    }

    public String getCodePass() {
        return codePass;
    }
}

